package com.lmx.repoDomain.repository;

import io.katharsis.queryParams.QueryParams;
import io.katharsis.repository.annotations.JsonApiFindAll;
import io.katharsis.repository.annotations.JsonApiResourceRepository;
import io.katharsis.repository.annotations.JsonApiSave;

import java.util.Map;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lmx.common.util.CommonUtil;
import com.lmx.persistence.service.EmployeeLeaveFlowService;
import com.lmx.repoDomain.tmodel.EmployeeLeaveFlow;

/**
 * 员工请假流程
 *
 * @author ytche
 * @date 2017年7月12日
 *
 */
@JsonApiResourceRepository(EmployeeLeaveFlow.class)
@Component
public class EmployeeLeaveFlowRepository extends
		BaseRepository<EmployeeLeaveFlow> {
	@Autowired
	EmployeeLeaveFlowService service;

	@PostConstruct
	public void init() {
		dslJpaService.setEntityClass(EmployeeLeaveFlow.class);
	}

	@Override
	@JsonApiFindAll
	public Iterable<EmployeeLeaveFlow> findAll(final QueryParams requestParams) {
		Map<String, String> filter = CommonUtil
				.getKeyMapByFilter(requestParams);
		if (filter.containsKey("staffIds")) {
			return service.recordLeaveStatus(filter);
		}
		return super.findAll(requestParams);
	}

	@Override
	@JsonApiSave
	public EmployeeLeaveFlow save(final EmployeeLeaveFlow entity) {
		return this.service.save(entity);
	}

}
